package heuristicFunctions;

import domain.PacmanBoard;
import aima.core.search.framework.HeuristicFunction;
import aima.core.util.datastructure.XYLocation;

public class ManhattanDistance implements HeuristicFunction {
	@Override
    public double h(Object state)
    {
        final PacmanBoard board = (PacmanBoard) state;
        final XYLocation actor = board.getPacmanLocation();
        final XYLocation finish = board.getFinishLocation();
        final double cost = 1d;
        if(finish != null)
        	return cost * (Math.abs(actor.getXCoOrdinate() - finish.getXCoOrdinate()) + Math.abs(actor.getYCoOrdinate() - finish.getYCoOrdinate()));
        return 0;
    }
}
